//
//  GHSOrderViewController.m
//  penzer
//
//  Created by 还带大道 on 2018/11/14.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "GHSOrderViewController.h"
#import "SPSelectScrollView.h"
#import "SPSliderScrollView.h"
#import "GHSDFHViewController.h"
#import "GHSDSHViewController.h"
#import "GHSDPJViewController.h"
#import "GHSSHViewController.h"

@interface GHSOrderViewController ()<UIScrollViewDelegate>
@property (nonatomic,weak) SPSelectScrollView *topScrollView;
@property (nonatomic,strong) CAGradientLayer *gl;
@property (nonatomic,weak) SPSliderScrollView *bottomScrollView;

@end

@implementation GHSOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"订单管理";
    [self setupNavRightBtn];
    [self setupTopView];
    [self setupBottomView];
    [self.topScrollView selectedWithIndex:0];
    
}



- (void)setupNavRightBtn
{
    UIButton *search = [[UIButton alloc] init];
    search.backgroundColor = [UIColor clearColor];
    [search addTarget:self action:@selector(onClickSearch) forControlEvents:UIControlEventTouchUpInside];
    [search setImage:[UIImage imageNamed:@"icon_search"] forState:UIControlStateNormal];
    [search setTitle:@" 搜索" forState:UIControlStateNormal];
    [search setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    search.titleLabel.font = [UIFont systemFontOfSize:15];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:search];
    
}


- (void)setupTopView
{
    SPSelectScrollView *topScrollView  = [SPSelectScrollView new];
    _topScrollView = topScrollView;
    [self.view addSubview:topScrollView];
    [topScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.mas_equalTo(45);
    }];
    
    self.topScrollView.backgroundColor = [UIColor whiteColor];
    NSArray *item = @[@"待发货",@"待收货",@"待评价",@"退货/售后"];
    self.topScrollView.btnOnClickBlock = ^(NSInteger index) {
        [self topBtnOnClickWithIndex:index];
    };
   
    self.topScrollView.indicatorBar_height = 4;
    self.topScrollView.item_textColor_nomal = RZ_COLOR(137, 136, 139);
    self.topScrollView.item_textColor_selected = RZ_COLOR(89, 11, 195);
    self.topScrollView.item_font_nomal = [UIFont fontWithName:@"PingFangSC-Medium" size:15];
    self.topScrollView.item_font_selected = [UIFont fontWithName:@"PingFangSC-Semibold" size:15];
    self.topScrollView.firstItem_leftMargin = 0;
    self.topScrollView.item_margin = 0;
    self.topScrollView.item_inset = 5;
    self.topScrollView.average = YES;
    self.topScrollView.items = item;
    
    
    //为指示条添加渐变色
    CALayer *layer = self.topScrollView.indicatorBar.layer;
    CAGradientLayer *gl = [CAGradientLayer layer];
    _gl = gl;
    gl.frame = layer.bounds;
    gl.startPoint = CGPointMake(0, 0);
    gl.endPoint = CGPointMake(1, 1);
    gl.colors = @[(__bridge id)RZ_COLOR(48, 35, 174).CGColor,(__bridge id)RZ_COLOR(200, 109, 215).CGColor];
    gl.locations = @[@(0),@(1.0f)];
    [layer addSublayer:gl];
    
    layer.shadowColor = RZ_COLOR(238, 217, 255).CGColor;
    layer.shadowOffset = CGSizeMake(0,2);
    layer.shadowRadius = 6;
    layer.shadowOpacity = 1;
    layer.shadowPath = [UIBezierPath bezierPathWithRect:layer.bounds].CGPath;
    self.gl.cornerRadius = self.topScrollView.indicatorBar_height*0.5;
    
}


- (void)setupBottomView
{
    SPSliderScrollView *sliderV = [SPSliderScrollView new];
    _bottomScrollView = sliderV;
    [self.view addSubview:sliderV];
    sliderV.scrollViewDidEndDeceleratingBlock = ^(NSInteger cureentPage) {//滚动了
        [self.topScrollView selectedWithIndex:cureentPage];
    };
    [sliderV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topScrollView.mas_bottom).offset(15);
        make.left.right.bottom.equalTo(self.view);
    }];
    
    NSArray<NSString *> *classNames = @[@"GHSDFHViewController",@"GHSDSHViewController",@"GHSDPJViewController",@"GHSSHViewController"];
    NSMutableArray<UIView *> *views = [NSMutableArray array];
    [classNames enumerateObjectsUsingBlock:^(NSString * _Nonnull className, NSUInteger idx, BOOL * _Nonnull stop) {
        UIViewController *vc = [NSClassFromString(className) new];
        if(vc){
            [self addChildViewController:vc];
            [views addObject:vc.view];
        }
    }];
    sliderV.views = views;
   
}




- (void)topBtnOnClickWithIndex:(NSInteger)index
{
    RZLog(@"----%ld",index);
    _gl.frame = self.topScrollView.indicatorBar.layer.bounds;
    [self.bottomScrollView selectedWithPage:index animateWithDuration:0];
    
    //刷新数据
    [self refresh];
}


- (void)refresh
{
    
}


- (void)onClickSearch
{
    RZLog(@"onClickSearch");
}
@end
